#include <block.h>
Public Member Functions | |
DBlock (int size, void(*err_function)(char *)=NULL) | |
~DBlock () | |
Type * | New () |
void | Delete (Type *t) |
Private Types | |
typedef DBlock::block_item_st | block_item |
typedef DBlock::block_st | block |
Private Attributes | |
int | block_size |
block * | first |
block_item * | first_free |
void(* | error_function )(char *) |
Classes | |
union | block_item_st |
struct | block_st |
Definition at line 202 of file block.h.
typedef struct DBlock::block_st DBlock< Type >::block [private] |
typedef union DBlock::block_item_st DBlock< Type >::block_item [private] |
DBlock< Type >::DBlock | ( | int | size, | |
void(*)(char *) | err_function = NULL | |||
) | [inline] |
Definition at line 209 of file block.h.
00209 { first = NULL; first_free = NULL; block_size = size; error_function = err_function; }
void DBlock< Type >::Delete | ( | Type * | t | ) | [inline] |
Definition at line 237 of file block.h.
00238 { 00239 ((block_item *) t) -> next_free = first_free; 00240 first_free = (block_item *) t; 00241 }
Type* DBlock< Type >::New | ( | ) | [inline] |
Definition at line 215 of file block.h.
00216 { 00217 block_item *item; 00218 00219 if (!first_free) 00220 { 00221 block *next = first; 00222 first = (block *) new char [sizeof(block) + (block_size-1)*sizeof(block_item)]; 00223 if (!first) { if (error_function) (*error_function)("Not enough memory!"); exit(1); } 00224 first_free = & (first -> data[0] ); 00225 for (item=first_free; item<first_free+block_size-1; item++) 00226 item -> next_free = item + 1; 00227 item -> next_free = NULL; 00228 first -> next = next; 00229 } 00230 00231 item = first_free; 00232 first_free = item -> next_free; 00233 return (Type *) item; 00234 }
int DBlock< Type >::block_size [private] |
void(* DBlock< Type >::error_function)(char *) [private] |
block_item* DBlock< Type >::first_free [private] |